/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.supplier;

import ejb.model.EJBModel;
import ejb.person.LanguageBeanRemote;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.NamingException;
import javax.swing.DefaultComboBoxModel;
import util.person.LanguageDetails;

/**
 *
 * @author Gebruiker
 */
public class LanguageComboboxModel extends DefaultComboBoxModel {

    @EJB
    private LanguageBeanRemote lbr;
    private ArrayList<LanguageDetails> languages;

    public LanguageComboboxModel() {
        lbr = (LanguageBeanRemote) EJBModel.getLanguageBean();
        languages = new ArrayList<LanguageDetails>();
        for (LanguageDetails language : lbr.getAllLanguageDetails()) {
            languages.add(language);
        }
    }

    @Override
    public Object getElementAt(int index) {
        return languages.get(index).getName();
    }

    @Override
    public int getSize() {
        return languages.size();
    }
    
    public Integer getId(int selected){
        return languages.get(selected).getId();
    }
    
    public int getIndexOf(Integer number) {
        int i = 0;
        for(LanguageDetails language:languages){
            if(language.getId().equals(number)){
                return i;
            }
            i++;
        }
        return 0;
    }
}
